---
category: Level 1 — Basic
created: '2020-02-28'
keywords:
title: Toggle an element
---

To toggle the element, we update the `display` property:

```js
const toggle = function (ele) {
    const display = ele.style.display;
    ele.style.display = display === 'none' ? 'block' : 'none';
};
```

## See also

-   [Set css style for an element](https://phuoc.ng/collection/html-dom/set-css-style-for-an-element/)
-   [Show or hide an element](https://phuoc.ng/collection/html-dom/show-or-hide-an-element/)
